<!-- <!DOCTYPE html> -->
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>微服务管理| Data Tables</title>
		<!-- Tell the browser to be responsive to screen width -->
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

		<!-- Bootstrap 3.3.7 -->
		<link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css">
		<!-- Font Awesome -->
		<link rel="stylesheet" href="../../bower_components/font-awesome/css/font-awesome.min.css">
		<!-- Ionicons -->
		<link rel="stylesheet" href="../../bower_components/Ionicons/css/ionicons.min.css">
		<!-- DataTables -->
		<link rel="stylesheet" href="../../bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<!-- Theme style -->
		<link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
		<!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
		<link rel="stylesheet" href="../../dist/css/skins/_all-skins.min.css">

		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
		  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
		  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
		  <![endif]-->

		<!-- Google Font -->
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<!-- <link rel="stylesheet/less" type="text/css" href="../../bower_components/bootstrap/dist/css/less/mixins/grid-framework.less" />
 -->
		<!-- <script src="less.min.js" type="text/javascript" ></script> -->
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>


		<style>
			/* 			.col-md-3.col-sm-4{
		float:right;
		width:7%;
		margin: 0 0.1%;
		height: 2%;
	}
	
	.col-md-3.col-sm-4:hover{
		background: #9D9D9D;
		border-radius: 4px;
	} */
	/*.btn-default ,.btn-danger{
	  background-color: #f4f4f4;
	  color: #444;
	  border-color: #ddd;
		float:right;
		margin: 0 0.5%;
		border:none;
		
	}
	.btn-default:hover{
		background: #337ab7;
		color: white;
	}*/
	
	
	.input-group{
		margin: 2%;
	}
	
</style>
	</head>
	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">

			<header class="main-header">
				<!-- Logo -->
				<a href="#" class="logo">
					<!-- mini logo for sidebar mini 50x50 pixels -->
					<span class="logo-mini"><b>A</b>LT</span>
					<!-- logo for regular state and mobile devices -->
					<span class="logo-lg"><b>Admin</b>LTE</span>
				</a>
				<!-- Header Navbar: style can be found in header.less -->
				<nav class="navbar navbar-static-top">
					<!-- Sidebar toggle button-->
					<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</a>

					<div class="navbar-custom-menu">
						<ul class="nav navbar-nav">
							<!-- Messages: style can be found in dropdown.less-->
							<li class="dropdown messages-menu">

								<ul class="dropdown-menu">


								</ul>
							</li>
							<!-- Notifications: style can be found in dropdown.less -->

							<!-- User Account: style can be found in dropdown.less -->
							<li class="dropdown user user-menu">
								<a href="#" class="dropdown-toggle" data-toggle="dropdown">
									<img src="../../dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
									<span class="hidden-xs">山西大汉</span>
								</a>
								<ul class="dropdown-menu">
									<!-- User image -->
									<li class="user-header">
										<img src="../../dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">

										<p>
											山西大汉 - Web Developer
											<small>Member since Nov. 2012</small>
										</p>
									</li>
									<!-- Menu Body -->
									<li class="user-body">
										<div class="row">
											<div class="col-xs-4 text-center">
												<a href="#">Followers</a>
											</div>
											<div class="col-xs-4 text-center">
												<a href="#">Sales</a>
											</div>
											<div class="col-xs-4 text-center">
												<a href="#">Friends</a>
											</div>
										</div>
										<!-- /.row -->
									</li>
									<!-- Menu Footer-->
									<li class="user-footer">
										<div class="pull-left">
											<a href="#" class="btn btn-default btn-flat">Profile</a>
										</div>
										<div class="pull-right">
											<a href="#" class="btn btn-default btn-flat">Sign out</a>
										</div>
									</li>
								</ul>
							</li>
							<!-- Control Sidebar Toggle Button -->

						</ul>
					</div>
				</nav>
			</header>
			<!-- Left side column. contains the logo and sidebar -->
			<aside class="main-sidebar">
				<!-- sidebar: style can be found in sidebar.less -->
				<section class="sidebar">
					<!-- Sidebar user panel -->
					<div class="user-panel">
						<div class="pull-left image">
							<img src="../../dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
						</div>
						<div class="pull-left info">
							<p>山西大汉</p>
							<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
						</div>
					</div>
					<!-- search form -->

					<!-- /.search form -->
					<!-- sidebar menu: : style can be found in sidebar.less -->
					<ul class="sidebar-menu" data-widget="tree">


						<li class="treeview active">
							<a href="#">
								<i class="fa fa-table"></i> <span>表格</span>
								<span class="pull-right-container">
									<i class="fa fa-angle-left pull-right"></i>
								</span>
							</a>
							<ul class="treeview-menu">
								<li><a href="list_page.html"><i class="fa fa-circle-o"></i>内部服务列表页</a></li>
                				<li>
									<a href="outside_list_page.html"><i class="fa fa-circle-o"></i>外部服务列表页</a>
								</li>
								<li><a href="dock_party_page.html"><i class="fa fa-circle-o"></i> 接入方列表</a></li>
								<li>
									<a href="user_authority.html"><i class="fa fa-circle-o"></i>用户权限管理</a>
								</li>
							</ul>
						</li>
						<li class="treeview active">
							<a href="#">
								<i class="fa fa-edit"></i> <span>表单</span>
								<span class="pull-right-container">
									<i class="fa fa-angle-left pull-right"></i>
								</span>
							</a>
							<ul class="treeview-menu">
								<li>
									<a href="test_service.html"><i class="fa fa-tumblr"></i>内部服务测试</a>
								</li>
							</ul>
						</li>
					</ul>	
				</section>
				<!-- /.sidebar -->
			</aside>

			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h1>
						微服务管理系统

					</h1>
					<ol class="breadcrumb">
						<li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
						<li><a href="#">列表服务</a></li>
						<li class="active">接入方服务</li>




					</ol>
				</section>

				<div class="box">
					<div class="box-header">
						<div class="col-sm-6">
							<h3 class="box-title">接入方服务列表</h3>
						</div>
                        <div class="col-sm-4">
                                <label for="apiNameForSearch" style="padding-top: 15px;float: left;margin-right: 5px;">接入方标识名&nbsp;</label>
                                <div class="input-group input-group-sm" style="width: 220px;">
                                    <input type="text"  class="form-control pull-right" name="userNameForSearch" id="userNameForSearch" onkeypress="return huichesearchUser()">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default" id="userNameSearch"  style="float: left;" onclick="searchInfoUser();"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                        </div>
						<button type="button" class="btn btn-danger" style="float: right; margin-right: 2%;" onclick="delServer();">

							<i class="fa fa-fw fa-times-circle"></i>
							删除
						</button>


						<button type="button" class="btn btn-default" style="float: right; margin-right: 2%;" onclick="addServerList();">
							<i class="fa fa-fw fa-plus-circle"></i>
							新增
						</button>




						<!-- 模态框（Modal） -->
						<div class="modal fade" id="serverListAddModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
						 aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
										<h4 class="modal-title" id="myModalLabel">新增接入方</h4>
									</div>

									<div class="modal-body">
										<input type="hidden" class="form-control" name="flag" id="flag">
										<form id="addServer" class="form-horizontal">
											<div class="box-body">
												<label for="tagName" class="col-sm-3 control-label">接入方标识名</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="tagName" id="tagName">
													</div>
												</div>
												<label for="remark" class="col-sm-3 control-label">接入方描述</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="remark" id="remark">
													</div>
												</div>
												<label for="userName" class="col-sm-3 control-label">接入方姓名</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="userName" id="userName">
													</div>
												</div>
												<label for="userMobile" class="col-sm-3 control-label">接入方电话</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="userMobile" id="userMobile">
													</div>
												</div>
												<label for="userEmail" class="col-sm-3 control-label">接入方邮箱</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="userEmail" id="userEmail">
													</div>
												</div>
												<label for="apiKey" class="col-sm-3 control-label">分配给接入方的key</label>
												<div class="form-group">
													<div class="col-sm-7">
														<input type="text" class="form-control" name="apiKey" id="apiKey">
														<button type="button" class="btn btn-block btn-danger btn-lg create_key " onclick="changeKeyOrScrect()">生成Key</button>
													</div>
												</div>
												<label for="apiSecret" class="col-sm-3 control-label">分配给接入方的秘钥</label>
												<div class="form-group">
													<div class="col-sm-7">


														
															<input type="text" class="form-control" name="apiSecret" id="apiSecret">
															
															<button type="button" class="btn btn-block btn-danger btn-lg create_screct" onclick="changeKeyOrScrect()">生成Sercet</button>
															
														

													</div>
												</div>

											</div>
										</form>
									</div>


									<div class="modal-footer">
										<button type="button" class="btn btn-default " data-dismiss="modal">关闭</button>
										<button type="button" class="btn btn-primary" onclick="saveServer();">提交</button>
									</div>
								</div><!-- /.modal-content -->
							</div><!-- /.modal -->
						</div>
					</div>
					<!-- /.box-header -->
					<div class="box-body">
						<table id="example1" class="table table-bordered table-striped">

							<thead>
								<tr>
									<th> </th>
									<th>序号</th>
									<th>接入方标识名</th>
									<th>描述</th>
									<th>对接人姓名</th>
									<th>对接人电话</th>
									<th>对接人邮箱</th>
									<th>创建时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>

								<tr>
									<th> </th>
									<td>Gecko</td>
									<td>Netscape 7.2</td>
									<td>Win 95+ / Mac OS 8.6-9.2</td>
									<td>1.7</td>
									<td>A</td>
									<td>Gecko</td>
									<td>Netscape 7.2</td>
									<td>Win 95+ / Mac OS 8.6-9.2</td>
								</tr>
								<tr>
									<th> </th>
									<td>Gecko</td>
									<td>Netscape Browser 8</td>
									<td>Win 98SE+</td>
									<td>1.7</td>
									<td>A</td>
									<td>Gecko</td>
									<td>Netscape 7.2</td>
									<td>Win 95+ / Mac OS 8.6-9.2</td>

								</tr>


							</tbody>

						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<!-- /.box -->
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
		</section>
		<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->


		<!-- Control Sidebar -->



		</ul>
		<!-- Tab panes -->



		</div>
		<!-- ./wrapper -->

		<!-- jQuery 3 -->
		<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
		<!-- Bootstrap 3.3.7 -->
		<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<!-- DataTables -->
		<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
		<!-- SlimScroll -->
		<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
		<!-- FastClick -->
		<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
		<!-- AdminLTE App -->
		<script src="../../dist/js/adminlte.min.js"></script>
		<!-- AdminLTE for demo purposes -->
		<script src="../../dist/js/demo.js"></script>
		<script src="common.js"></script>
		<!-- page script -->
		<script>
			var DataTablePaging = {
				language: { // 汉化
					zh_cn: {
						"sProcessing": "正在加载数据...",
						// "sLoadingRecords": "载入中...",
						"sLengthMenu": "显示&nbsp;_MENU_&nbsp;条 ",
						"sZeroRecords": "没有您要搜索的内容",
						"sInfo": "从_START_ 到 _END_ 条&nbsp;&nbsp;&nbsp;&nbsp;共 _TOTAL_ 条",
						"sInfoEmpty": "记录数为0",
						"sInfoFiltered": "(全部记录数 _MAX_  条)",
						"sInfoPostFix": "",
						"sSearch": "搜索",
						"sUrl": "",
						"oPaginate": {
							"sFirst": "第一页",
							"sPrevious": " 上一页 ",
							"sNext": " 下一页 ",
							"sLast": " 最后一页 "
						}
					}
				}
			};
			$(function() {
				$('#example1').DataTable({
					"oLanguage": DataTablePaging.language.zh_cn,
					'paging': true,
					'lengthChange': false,
					'searching': false,
					'info': true,
					'width': '100%',
					'autoWidth': true,
					"scrollY": "calc(80vh - 111px)", //表格内容部分高度设置为窗口高度-100px
					"scrollX": false, //横向滚动条
					"scrollCollapse": true,
					//"ordering": false,
					/*****/
					"fixedHeader": true,
					"responsive": true,
					"columnDefs":[{
					　　　　'targets' : [0,1,3,4,5,6,8],    //除第2外，都默认不排序
					　　　　'orderable' : false
					　　}],
					'ajax': {
						"url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
						"dataType": "json",
						"data": function(d) {
							d.Head = {
								"ApiName": "getUserList",
								"Model": "debug"
							};
							d.Body = {
								"tName":$("#userNameForSearch").val()
							}
							return JSON.stringify(d)
						},
						"dataSrc": "Body",
					},
					"columns": [{
							"data": "tagName",
							'width': "5%",
							'class': 'text-center',
							"render": function(data, type, full) {
								// var i = '<div class="radio"><label><input type="radio" name="mealReimIdRadio" value="' + data +
								// 	'" data-status = "' + full.mealReimStatus + '" data-date = "' + full.mealInvoiceDate +
								// 	'" data-employee = "' + full.mealReimEmployee + '"></label></div>';
								var i = '<div class="radio"><label><input type="radio" name="tagName" value="' + data +
									'"></label></div>';
								return i;
							}
						},
						{
							"data": " ",
							'width': "5%",
							//"title": "用户名",
							'class': 'text-center',
							"render": function(data, type, full, meta) {
								return meta.settings._iDisplayStart + meta.row + 1;
							}
						},
						{
							"data": "tagName",
							'width': "10%",
							'class': 'text-center',
							//"title": "用户名",
						},

						{
							"data": "remark",
							'class': 'text-center',
							'width': "10%",
						},

						{
							"data": "userName",
							'class': 'text-center',
							'width': "10%",
						},

						{
							"data": "userMobile",
							'class': 'text-center',
							'width': "10%",
						},
						{
							"data": "userEmail",
							'class': 'text-center',
							'width': "10%",
						},

						{
							"data": "createTime",
							'class': 'text-center',
							'width': "12.5%",
						},
						{
							"data": "",
							'width': "12.5%",
							'class': 'text-center',
							"mRender": function(data, type, full) {

								return "<a href=\"javascript:void(0);\" style=\"cursor: pointer;color:#333\" class=\"label label-primary  \" onclick=\"addServerList('" +
									full.tagName + "');\" >" +
									"配置</a>";

							}
						}
					],
					/*******/
				})
			});





			function addServerList(name) {

				if (name != null && name != undefined && name != '') {
					// 接入方操作-请求后台数据并打开接入方模态框
					// 设置弹框标识
					$("#flag").val("true");
					$("#tagName").attr("readonly", "readonly");
					//alert(name)
					$.ajax({
						"url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
						"async": true,
						"data": JSON.stringify({
							"Head": {
								"ApiName": "getUserByName",
								"Model": "debug",

							},
							"Body": {
								"tagName": name
							}
						}),
						// 成功后开启模态框
						success: showModal,
						error: function() {
							alert("系统繁忙，请稍后重试");
						},
						dataType: "json"
					});
					/*$.ajax({
            "url": 'test.json',
      //"type": "POST",
      "dataSrc":"",
      // 成功后开启模态框
            success : showModal,
            error : function() {
                alert("系统繁忙，请稍后重试");
            },
        });*/
				} else {
					// 新增操作-打开模态框
					$("#flag").val("");
					$("#serverListAddModal").modal({ //serverListAddModal
						backdrop: false, // 点击空白不关闭
						keyboard: false, // 按键盘esc不关闭
					});
				}

			};


			// 查询成功后向模态框插入数据并开启模态框。data是返回的JSON对象
			function showModal(data) {

				$("#tagName").val(data.Body.tagName);
				$("#remark").val(data.Body.remark);
				$("#userName").val(data.Body.userName);
				$("#userMobile").val(data.Body.userMobile);
				$("#userEmail").val(data.Body.userEmail);
				$("#apiKey").val(data.Body.apiKey);
				$("#apiSecret").val(data.Body.apiSecret);

				// 显示模态框
				//$('#serverListAddModal').modal('show');
				// 打开模态框
				$("#serverListAddModal").modal({
					backdrop: false, // 点击空白不关闭
					keyboard: false, // 按键盘esc不关闭
				});
			};


			//追加生成 key 或者 screct 的功能	 
			function changeKeyOrScrect() {
				$(".create_key").click(function() {
					str = createKeyOrScrect(10)
					$(this).parent().children("input").val(str)
				})

				$(".create_screct").click(function() {
					str = createKeyOrScrect(20)
					$(this).parent().children("input").val(str)
				})
			};

			//生成 随机 key  和 screct
			function createKeyOrScrect(len) {
				res = '';
				ch = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
				chs = ch.split('')
				for (i = 0; i < len; i++) {
					id = Math.ceil(Math.random() * (chs.length - 1))
					res += chs[id];
				}
				return res;
			};

			// 删除服务
			function delServer() {
				// 获取选中的服务名称
				var tagName = $('input:radio[name="tagName"]:checked').val();
				if (tagName == null || tagName == '' || tagName == undefined) {
					alert("请选择一条数据");
				} else {
					// 删除
					if (window.confirm('你确定要删除服务吗？')) {
						$.ajax({
							"url": apiUrl,
							"type": "POST",
							"contentType": "application/json;charset=utf-8",
							"async": true,
							"data": JSON.stringify({
								"Head": {
									"ApiName": "delUser",
									"Model": "debug"
								},
								"Body": {
									tagName: tagName
								}
							}),
							// 成功后开启模态框
							success: function(d) {
								var status = d.Head.Status;
								if (status != null && status != undefined && status != '' && status == '0') {
									// 删除成功-刷新页面
									window.location.reload();
								} else {
									// 删除失败，弹框提示
									alert(d.Head.Exception[0].desc)
								}
							},
							error: function() {
								alert("系统繁忙，请稍后重试");
							},
							dataType: "json"
						});
					} else {
						return false;
					}
				}

			};

			// 选中一行即为选中
			$('#example1 tbody').on('click', 'tr', function() {
				$(this).find("td").find("input:radio").prop('checked', 'checked');
			});


			// 保存 & 修改 服务信息
			function saveServer() {
				flag = $("#flag").val();
				if (flag != null && flag != undefined && flag != '' && flag == 'true') {
					// 配置操作提交
					var jsonData = getFormData();
					$.ajax({
						"url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
						"async": true,
						"data": JSON.stringify({
							"Head": {
								"ApiName": "updateUser",
								"Model": "debug"
							},
							"Body": jsonData
						}),
						// 成功后开启模态框
						success: function(d) {
							var status = d.Head.Status;
							if (status == "0") {
								// 添加成功-关闭模态框&刷新页面
								$("#serverListAddModal").on("hidden.bs.modal", function() {
									$(this).removeData("bs.modal");
									document.getElementById("addServer").reset();
								});
								window.location.reload();
							} else {
								// 添加失败，弹框提示
								alert(d.Head.Exception[0].desc)
							}
						},
						error: function() {
							alert("系统繁忙，请稍后重试");
						},
						dataType: "json"
					});
				} else {
					// 新增操作提交
					var jsonData = getFormData();
					$.ajax({
						"url": apiUrl,
						"type": "POST",
						"contentType": "application/json;charset=utf-8",
						"async": true,
						"data": JSON.stringify({
							"Head": {
								"ApiName": "newUser",
								"Model": "debug"
							},
							"Body": jsonData
						}),
						// 成功后开启模态框
						success: function(d) {
							var status = d.Head.Status;
							if (status != null && status != undefined && status != '' && status == '0') {
								// 添加成功-关闭模态框&刷新页面
								$("#serverListAddModal").on("hidden.bs.modal", function() {
									$(this).removeData("bs.modal");
									document.getElementById("addServer").reset();
								});
								window.location.reload();
							} else {
								// 添加失败，弹框提示
								alert(d.Head.Exception[0].desc)
							}
						},
						error: function() {
							alert("系统繁忙，请稍后重试");
						},
						dataType: "json"
					});

				}
			};

			//取容器内所有 input 组装成 json
			function getFormData(sel) {
				json = {};
				$("#addServer input,#addServer textarea").each(function() {
					json[$(this).attr("name")] = $(this).val();
				});
				json["serviceStatus"] = $("input[name='serviceStatus']:checked").val()
				return json;
			};
			
			function searchInfoUser() {
		        $("#example1").DataTable().ajax.reload();
		    };
		    
		    function huichesearchUser(){//回车搜索
		        var keyCode =event.keyCode;
		        if(keyCode== 13){
		            searchInfoUser();
		            return false;
		        }
		    };
		</script>
	</body>
</html>
